package woaini.fenger.task.init;

import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;
import woaini.fenger.core.base.boot.ApplicationStartupCompleted;
import woaini.fenger.core.task.BotTaskManager;

/**
 * 机器人任务自动初始化
 *
 * @see woaini.fenger.task.init.BotTaskAutoInit
 * @author yefeng {@code @Date} 2023-05-16 16:50:39
 */
@Component
@AllArgsConstructor
public class BotTaskAutoInit implements ApplicationStartupCompleted {

  private BotTaskManager botTaskManager;

  @Override
  public void onInit() {
    signIn();
    heart();
  }

  public void signIn() {
    String name = "签到打卡";
    String group = "每日签到";

    boolean existsTask = botTaskManager.isExistsTask(name, group);
    if (!existsTask) {
      // 加载签到
      botTaskManager.createCornTask(name, group, "0 0 1 * * ? *", "用于签到打卡", null);
    }
  }

  public void heart() {
    String name = "心跳";
    String group = "心跳";

    boolean existsTask = botTaskManager.isExistsTask(name, group);
    if (!existsTask) {
      botTaskManager.createCornTask(name, group, "0/10 * * * * ? *", "用于保持心跳", null);
    }
  }

  @Override
  public int order() {
    return 200;
  }
}
